<?php
defined('IN_LK') or die('Access Denied');
lk::lo_app('admin_common', 'admin', 0);
class develop_log extends admin_common
{
	/**
	 * 数据操作句柄
	 */
	private $db;
	
	public function __construct()
	{
		parent::__construct();
		$this->db = lk::load_model('develop_log');
	}
	
	public function initialize()
	{
		lk::lo('form');
		$ac = isset($_GET['ac']) ? (int)$_GET['ac'] : 1;
		$_GET['page'] = isset($_GET['page']) ? (int)$_GET['page'] : 1;
		$logs = $this->db->listinfo('*', '', $_GET['page'], 10, '`did` DESC');
		$page_nav = $this->db->page_nav;
		include self::admin_t('develop_log');
	}
	
	/**
	 * 错误日志
	 *
	 */
	public function errorlog()
	{
		$log = array();
		$content = '';
		$log_arr = explode("\n", read_log());
		arsort($log_arr);
		foreach($log_arr as $log_item)
		{
			$log[] = explode('_@#', $log_item);
		}
		include self::admin_t('error_log');
		//$str = preg_replace("/<a\s+[^>]+>(.*)<\/a>/U", "\${1}", $str);
	}
	
	/**
	 * 添加日志
	 *
	 */
	public function add_log()
	{
		if(isset($_POST['dosubmit']))
		{
			$info = $_POST['info'];
			$log_fields = array('change_type', 'change_log');
			foreach($info as $key => $value)
			{
				if(!in_array($key, $log_fields))
				{
					unset($info[$k]);
				}
			}
			$info['change_log'] = new_htmlspecialchars_decode($info['change_log']);
			$lastversion  = $this->db->get_one('version', '', '`did` DESC');
			if($lastversion)
			{
				$lastv = (int)$lastversion['version'];
			}
			$info['time'] = date('Y-m-d H:i:s', TIME);
			$info['developer'] = 'yangzhiguo';
			$info['version']   = ++$lastv;
			if($this->db->insert($info))
			{
				showmsg(LANG('update_success'), true, '?m=admin&c=develop_log&ac=1');
			}
			else
			{
				showmsg(LANG('update_false'), false, '?m=admin&c=develop_log&ac=2');
			}
		}
	}
	
}